package com.librariy.util;

import android.content.Context;

import java.io.File;

/**
 * 需要访问的网址集中在这里
 * 
 * @author 易申
 *
 */
public class ZorenCache {
    private static final String TAG = "ZorenCache";
    public static File initCacheDir(final Context mContext,String mType,File mCacheDir) {
        if(mCacheDir!=null&&mCacheDir.isDirectory()) return mCacheDir;
        File mTempCacheDir=new File(mContext.getExternalCacheDir(),mType);
        if(!mTempCacheDir.exists()){
            mTempCacheDir.mkdirs();
        }
        if(!mTempCacheDir.isDirectory()){
            //mTempCacheDir=null;
        }
        return mTempCacheDir;
    }
    public static void clearCacheDir(File mCacheDir) {
        long currentTime=System.currentTimeMillis();
        for(File f:mCacheDir.listFiles()){
            //一个小时内的数据，保留，否则删除
            if(currentTime-f.lastModified()<3600*1000) continue;
            Log.d(TAG, "---------Delete File="+f.getAbsolutePath());
            f.delete();
        }
    }

}
